package com.lwq.designpattern.structuralPatterns.flyweightPattern;

/**
 * @author liwq
 * @description
 * @date 2021/11/29 14:39
 */
public class Demo {
    private static final String colors[] = {"黑色", "白色"};

    public static void main(String[] args) {
        // 两人下五子棋，黑色先下，共走20步
        for (int i = 1; i <= 20; ++i) {
            FiveInARowChess chess = null;
            if (i % 2 != 0) {
                chess = (FiveInARowChess)ChessFactory.getCircle(colors[0]);
            } else {
                chess = (FiveInARowChess)ChessFactory.getCircle(colors[1]);
            }
            chess.setX(getRandomX());
            chess.setY(getRandomY());
            chess.play();
        }
    }

    private static int getRandomX() {
        return (int)(Math.random() * 100);
    }

    private static int getRandomY() {
        return (int)(Math.random() * 100);
    }
}
